import 'package:flutter/material.dart';
import 'package:yysk_app/utils/colors.dart';
import 'package:yysk_app/utils/helper.dart';
import 'package:yysk_app/widget/lazy_network_image.dart';

class CheckboxWidget extends StatelessWidget {
  final bool checked;
  final ValueChanged<bool>? onChanged;
  final ValueChanged<int>? onBindValue;
  final double? size;
  final Widget? label;
  final Color? color;
  final int? bindValue;
  const CheckboxWidget({
    super.key,
    required this.checked,
    this.size = 18,
    this.label,
    this.color = Colors.black,
    this.onChanged,
    this.bindValue,
    this.onBindValue,
  });

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        GestureDetector(
          onTap: () {
            _onChanged();
          },
          child: SizedBox(
            width: 24,
            height: 18,
            child: Center(
              child: Image.asset(
                checked
                    ? 'static/images/active_check.png'
                    : 'static/images/default_check.png',
                width: size,
                height: size,
                cacheWidth:
                    (size! * MediaQuery.of(context).devicePixelRatio)
                        .ceil(), // 转换为物理像素
                cacheHeight:
                    (size! * MediaQuery.of(context).devicePixelRatio).ceil(),
              ),
            ),
          ),
        ),
        label != null ? label! : SizedBox(),
      ],
    );
  }

  void _onChanged() {
    if (bindValue != null) {
      onBindValue!(bindValue!);
    }
    if (onChanged != null) {
      onChanged!(!checked);
    }
  }
}
